<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    //构建一个计算器函数：参数（计算法则，数字1，数字2）、构建一个计算平均值函数，在函数中执行 1.求和，2.求平均数，3.求每个数字与平均数的差
    function jsq(rule, n1, n2) {
        switch (rule) {
            case "+":
                return n1 + n2;
                break;
            case "-":
                return n1 - n2;
                break;
            case "*":
                return n1 * n2;
                break;
            case "/":
                return n1 / n2;
                break;
        }
    }
    function avg(){
        let num1 = 5, num2 = 10;
        let result = jsq("+",num1,num2);
        console.log(result);

        let avgVal = jsq("/",result,2);
        console.log(avgVal);

        let avgs1 = jsq("-",num1,avgVal);
        let avgs2 = jsq("-",num2,avgVal);
        console.log(avgs1);
        console.log(avgs2);
    }
    avg();
</script>

</html>